<?php
namespace ShadowVc\Utils;

/**
 * 请求抽象类
 *
 * @author chenxiaochun
 *
 */
abstract class EopRequest {

  /**
   * api名称
   */
  public abstract function getApiMethodName();

  /**
   * 获取所有应用参数
   */
  public function getApiParas() {
    $params = array();
    foreach (get_object_vars($this) as $key => $value) {
      if ($value === null) {
        continue;
      }
      if (is_array($value) || is_object($value)) {
        $params[$key] = json_encode($value);
      } else {
        $params[$key] = $value;
      }
    }
    return $params;
  }


  public function setParam($arr) {
    if (!is_array($arr)) {
      return;
    }
    $objKeys = array_keys(get_object_vars($this));
    foreach ($arr as $k => $v) {
      if (in_array($k, $objKeys)) {
        $this->$k = $v;
      }

    }
  }

  /**
   * 参数检查
   */
  public abstract function check();

}
